//  This file is part of Swordbible - http://www.swordwarrior.net
//  Copyright (C) 2003-2009 Manu Mital mital.manu@gmail.com

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


#pragma once


// CNotesPage dialog

#include "CustomRs.h"
#include "MyToolBar.h"
#include "AutoRichEditCtrl.h"
#include "afxwin.h"


// Declare const array of font sizes
const static int nFontSizes[] = 
	{8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72};

class CNotesPage : public CPropertyPage
{
	DECLARE_DYNAMIC(CNotesPage)

public:
	inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
	CString verse_code;
	CString data;
	void LoadEnteringID (CString ID);
  void RecreateNoteLinks();
	void Delete();
	void CreateBlankRecord();
	void AddNew();
	void UpdateBoundData();
	void GenerateError(HRESULT hr, PWSTR pwszDescription);
	void CreateDatabaseX();
	void CompactDatabase();
	CNotesPage();
	virtual ~CNotesPage();
	BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR,   LRESULT *pResult);

// Dialog Data
	enum { IDD = IDD_NOTESPAGE };
	CAutoRichEditCtrl	m_notesCtrl;
	CMyToolBar m_wndFormatBar;
	CHARFORMAT cf_default;

	static CString ActiveMainFrameCommand;

protected:
	void OnUpdateRichEdit();
	void BibleSynch();

	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    afx_msg LONG OnBarReturn(UINT, LONG );
	afx_msg LONG OnChangeNotesChapter(UINT , LONG );
	afx_msg LONG OnChangeNotesBook(UINT , LONG );
	afx_msg LONG OnMainFrameCommand(UINT, LONG);
	
  static CString path;
	


	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnCharColor();
	afx_msg void OnCharItalic();
	afx_msg void OnUpdateCharItalic(CCmdUI* pCmdUI);
	afx_msg void OnCharUnderline();
	afx_msg void OnUpdateCharUnderline(CCmdUI* pCmdUI);
	afx_msg void OnInsertBullet();
	afx_msg void OnUpdateInsertBullet(CCmdUI* pCmdUI);
	afx_msg void OnParaCenter();
	afx_msg void OnUpdateParaCenter(CCmdUI* pCmdUI);
	afx_msg void OnParaLeft();
	afx_msg void OnUpdateParaLeft(CCmdUI* pCmdUI);
	afx_msg void OnParaRight();
	afx_msg void OnUpdateParaRight(CCmdUI* pCmdUI);
	afx_msg void OnCharBold();
	afx_msg void OnUpdateCharBold(CCmdUI* pCmdUI);
	afx_msg void OnRtfCopy();
	afx_msg void OnRtfCut();
	afx_msg void OnRtfPaste();
	afx_msg void OnRtfSave();
	afx_msg void OnSynch();
	afx_msg void OnUpdateSynch(CCmdUI* pCmdUI);
	afx_msg void OnNotesPrint();
  afx_msg void OnInsertLink();
	afx_msg void OnDestroy();


private:
	void FillComboBoxes();  // helper function
	static int CALLBACK EnumFontFamProc(ENUMLOGFONT *lpelf, 
					NEWTEXTMETRIC *lpntm,
					int nFontType,
					LPARAM lParam);
	int oldCount;

	void RefreshBoundData();
	CCustomRs m_rsRecSet;
	CString m_strCmdText;
	CString m_strConnection;
	IADORecordBinding* m_piAdoRecordBinding;
	_RecordsetPtr m_pRs;

	BOOL CreateDB();
	BOOL IsPersonal;
public:
	
	CComboBox m_cmbBibleBook;
	CComboBox m_cmbBibleChapter;
	CComboBox m_cmbFontName;
	CComboBox m_cmbFontSize;

	afx_msg void OnSelectBibleBook();
	afx_msg void OnSelectBibleChapter();
	afx_msg void OnSelectFontName();
	afx_msg void OnSelectFontSize();

	afx_msg void OnEnMsgfilterRicheditNotes(NMHDR *pNMHDR, LRESULT *pResult);
 
  void OnPrevious();
	void OnNext();

	virtual BOOL OnSetActive();
  afx_msg void OnEnLinkRicheditNotes(NMHDR *pNMHDR, LRESULT *pResult);
};
